package com.pi.pro.xcmg.am.was.edi.infor.service;





import com.pi.common.utils.StringUtils;
import com.pi.common.utils.TextUtils;
import com.pi.config.InforWmsClientSecretConfig;
import com.pi.pro.xcmg.am.common.XcmgAmConstants;
import com.pi.pro.xcmg.am.was.edi.infor.common.InforWasExchangeSupport;
import com.pi.pro.xcmg.am.was.edi.infor.dto.reply.FuncReplyListData;
import com.pi.pro.xcmg.am.was.edi.infor.dto.reply.StorageLineResultDto;
import com.pi.pro.xcmg.am.was.edi.infor.dto.req.StorageQueryData;
import com.pi.wms.fac.conn.HttpAccessUrl;
import com.pi.wms.fac.conn.HttpConstants;
import com.pi.wms.fac.conn.HttpclientProxy;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;


/**
 */
@Getter
@Setter
public class StorageServiceProxy extends BaseInforExchangeServiceProxy {

    private HttpclientProxy wmsStorageClient;
    private HttpAccessUrl wmsStorageQueryPostAccessUrl;


    @Autowired
    private InforWmsClientSecretConfig secretConfig;

    //
    public FuncReplyListData<StorageLineResultDto> query(StorageQueryData params) {
        FuncReplyListData<StorageLineResultDto> replyData=null;
        String replyText = "";
        if (this.wmsStorageClient==null){
            return InforWasExchangeSupport.errorReplyList("install client error");
        }
        Map<String,String> headers = new HashMap<>();
        try{
            headers.put("Content-Type", XcmgAmConstants.HTTP_CONTENT_TYPE_HTTP_JSON);
            headers.put("sectionId", StringUtils.ifNullOrBlank(this.sectionId, secretConfig.getAppcode()));
            headers.put("token", StringUtils.ifNullOrBlank(this.token, secretConfig.getToken()));

            replyText = this.wmsStorageClient.post(this.wmsStorageQueryPostAccessUrl, null, headers,
                    HttpConstants.URL_METHOD_POST, TextUtils.toJsonText(params));
            replyData= InforWasExchangeSupport.parseListJson(replyText, StorageLineResultDto.class);
        }catch (Exception e){
            e.printStackTrace();
            replyText="send inventory query error.//"+e.getMessage();
            replyData= InforWasExchangeSupport.errorReplyList(replyText);
        }
        return replyData;
    }



}
